#pragma once

#include "RtpToPcap.h"
#include <stdio.h>
#include <vector>

#pragma pack(push, 1)
struct PcapFileHeader 
{
    uint32_t magic_number = 0xA1B2C3D4; // 小端模式用0xD4C3B2A1
    uint16_t version_major = 2;
    uint16_t version_minor = 4;
    int32_t  thiszone = 0;
    uint32_t sigfigs = 0;
    uint32_t snaplen = 65535;
    uint32_t linktype = 1; // Ethernet
};
#pragma pack(pop)

// 数据包头结构体
#pragma pack(push, 1)
struct PcapPacketHeader 
{
    uint32_t ts_sec;   // 时间戳秒
    uint32_t ts_usec;  // 时间戳微秒
    uint32_t incl_len; // 捕获长度
    uint32_t orig_len; // 原始长度
};
#pragma pack(pop)

class RtoToPcapImpl : public RtpToPcap
{
public:
    RtoToPcapImpl() = default;
    virtual ~RtoToPcapImpl();

    virtual int32_t open(const char* filename);

    virtual void writeRtpPacket(const uint8_t* pData, uint32_t bytes,
        uint32_t srcIp, uint16_t srcPort, uint32_t dstIp, uint16_t dstPort,
        uint32_t tv_sec, uint32_t tv_usec);

    virtual int32_t close();

private:
    FILE* m_fp = nullptr;
    std::vector<uint8_t> m_fullPacket;

};